<template>
	<view class="goodWrapper">
		<view class="goodContainer">
			<view class="searchInput">
				<view class="goodFilter">
					<uniIcon type="search" size="14" style="line-height: 50rpx;margin-left: 10rpx;margin-right: 10rpx;color: #a7aab3;" /><input
					 placeholder="输入商品名称/商品编号查询" class="searchOption" v-model="inputStr"></input>
					<button class="searchBt" @tap="suosuo()">查询</button>
				</view>
				<view class="searchOptions">
					<!-- <button class="giveSong"></button> -->
					<button class="getPicture" @tap="tel()"></button>
				</view> 
			</view>
			<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltoupper="upper" @scrolltolower="lower"
			 @scroll="scroll"> 
				<checkbox-group>
					<view class="goodsItem" v-for="(item,index) in GoodList" :key="index" @tap="navigatorTo()">
						<view class="checkboxContainer" >
							<!-- <view :class="['checkboxTemp',{'checkboxTempActive':checkindex==index}]" @tap="selectNowGood(index)"></view> -->
							<checkbox  :checked="checkindex==index" @tap="selectNowGood(index)" />
						</view>
						<image v-if="item.Goods_Image_Path1!=''" 
						 :src="'http://192.168.1.51:9000/picture'+item.Goods_Image_Path1" class="goodsImg"></image>
						<image v-else src="../../static/image/unUplad.png" class="goodsImg"></image>
						<view class="goodInfo">
							<view class="goodName">{{item.GoodsName}}
								<button @tap="lookGoodInfo(index)">商品设置</button>
							</view>
							<view class="priceWrap">
								<view class="price">
									<text>编号:{{item.GoodsCode}}</text>
								</view>
								<view class="price">
									<view><text>进货价:￥{{item.Price}}</text></view>
									<view>数量: <input type="number" v-model="item.Qty" maxlength="5"> </view>
								</view> 
								<view class="price">
									<view><text>库存:{{item.stockqty}}</text></view>
								</view>
							</view>
						</view>
					</view>
				</checkbox-group>
			</scroll-view>
		</view>
		<view class="goodsCount">
			<!-- <view @tap="AddCheckAll()">添加全部</view> -->
			<view @tap="addCheckGoodList()" style="background-color: #007AFF;color: #fff;">确定</view>
			<!-- <view>查看已选</view>
			<view>删除已选</view> -->
		</view>
	</view>
</template>
<script>
	import allConst from "../../Json.js"
	import uniIcon from '@/components/uni-icon/uni-icon.vue';
	import * as GetApi from '@/syApis/syHttp/Http.js';
	import * as CommonFun from "@/common/common.js";
	export default {
		data() {
			return {
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				GoodList: [],
				StoreID: 0,//仓库id 配出仓库id
				StoreID2:0,//配入仓库id
				stockName:'',//仓库名字
				isShowCar: false,
				// 多选商品复选框
				checkGoodList: [],
				//已选商品列表
				selectGoodList: [
					
				],
				//搜索框的条件
				inputStr: "",
				//单据类型
				orderType:2,
				//单据名称
				BillName:"",
				Isdistribution:0,//是否是配送订单
				tmpGoods:[],//单据商品,
				checkindex:-1,//单选的索引
				isNumQtStorm:false,
				// BillDetail:[],//源单
				//选择的供应商
				ClientID:""
			}
		},
		created() {

		},
		onShow() {
			// this.GoodList = this.GoodList;
			this.$eventHub.$off('GoodStting');
		},
		//初始化
		onLoad(options) {
			uni.showLoading({
				title: "加载中...",
					mask:false
			}) 
			console.log('仓库')
			console.log(this.StoreID)
			console.log('配入仓库')
			console.log(options.StoreID2)
			this.StoreID = options.StoreID;
			this.StoreID2 = options.StoreID2;
			this.orderType = options.orderType;
			this.BillName = options.name;
			this.ClientID = options.ClientID;
			this.Isdistribution = options.Isdistribution;
			this.batch = options.batch;
			this.isquote = options.isquote;
			// this.Order = JSON.parse(options.Order);//选中的商品
			this.stockName = options.stockName
			// console.log(options.Detail)
			// console.log(JSON.parse(options.Detail))
			// this.tmpGoods = JSON.parse(options.Detail);
			
			// var BillID = options.BillID
			//console.log('初始化成功!')
			//console.log(this.isquote)
			this.getGoodList();
			this.tmpGoods = JSON.parse(uni.getStorageSync("Detail",""));
			this.Order = JSON.parse(uni.getStorageSync("Order",""));
			console.log('----源单加载成功----')
			console.log(this.tmpGoods)
			console.log('选中的商品')
			console.log(this.Order)
			// uni.setStorageSync("Detail","")
			// uni.setStorageSync("Order","")
			// console.log('清空')
			// console.log()
			console.log(uni.getStorageSync("Detail"))
			var that = this
			//初始化 是否允许负库存出库
			let SystemSettingInfo = uni.getStorageSync("SystemSettingInfo", ""); //存储系统设置
			SystemSettingInfo = JSON.parse(SystemSettingInfo);
			SystemSettingInfo.forEach((item, index) => {
				if (item.SystemName == '是否允许负库存出库') {
					if (item.Value == "1") {
						that.isNumQtStorm = true;
					}
					// console.log(item.Value);
				}
			});
			
		},
		components: {
			uniIcon
		},
		// watch:{
		// 	// 数量不能超过10000
		// 	NowSelectGoods:{
		// 		handler:(values)=> {
		// 			//console.log(value)
		// 		},
		// 		deep:true
		// 	},
		// },
		methods: {
			//搜索
			suosuo() {
				//console.log("进行了搜索");
				uni.showLoading({
					title: "加载中...",
					mask:false
				})
				let data = {};
				if (this.inputStr == '') {
					data = {
						StoreID: this.StoreID,
						BillName:this.BillName
						// Filter:"GoodsName='"+this.inputStr+"'"
					};
				} else {
					data = {
						StoreID: this.StoreID,
						Filter: "GoodsName like '%" + this.inputStr + "%' or GoodsCode like '%" + this.inputStr + "%'",
						// Filter: "GoodsName like '%" + this.inputStr + "%'",
						BillName:this.BillName
					};
				}

				//console.log("条件是" + JSON.stringify(data));
				this.getGoodList(data);
			},
			
			// 添加全部
			AddCheckAll(){
				for(var i in this.GoodList){
					if(this.GoodList[i]["StoreID"] ==""||this.GoodList[i]["StoreID"] ==undefined){
						this.GoodList[i]["StoreID"] = this.StoreID
						this.GoodList[i]["stockName"] = this.stockName
					}
					if(this.GoodList[i]["IsGift"] ==""||this.GoodList[i]["IsGift"] ==undefined){
						this.GoodList[i]["IsGift"] ='否'
					}
				}
				this.$eventHub.$emit('Addfires', JSON.stringify(this.GoodList));
				uni.navigateBack({
					delta: 1
				})
			},

			//添加已选
			addCheckGoodList() {
				var that = this;
				if(that.checkindex == -1){
						uni.showToast({
							title: "请至少选择一件商品",
							duration: 1000,
							icon: "none"
						});
						return
				}
				var statu = false
				if(this.Isdistribution == true){
					statu = true
				}
				console.log('源单商品')
				console.log(this.tmpGoods)
				// return
				that.selectGoodList  = this.isidentical(this.tmpGoods,that.GoodList[that.checkindex],statu)
				// 选中的商品
				// that.selectGoodList = that.GoodList[that.checkindex];
				if(that.selectGoodList.Qty<=0 || that.selectGoodList.Qty == ""){
					uni.showToast({
						title: "商品数量不能少于一件",
						duration: 1000,
						icon: "none"
					});
					return;
				}
				// console.log('选中商品的数量')
				// console.log(that.selectGoodList.Qty)
				// return
				if(that.isNumQtStorm == true){
					if(that.selectGoodList.Qty > that.selectGoodList.stockqty){
						uni.showToast({
							title: "库存不足",
							duration: 1000,
							icon: "none"
						});
						return
					}
				}
				//判断是否是批号商品
				// console.log(that.selectGoodList)
				// console.log('批号')
				// console.log(that.selectGoodList.BatchNo)
				if(that.selectGoodList.IsBatch == true && (that.selectGoodList.BatchNo == "" || that.selectGoodList.BatchNo == undefined)){
					uni.showToast({
						title: "选中的商品为批号商品！，请点击商品右方进行设置",
						duration: 2000,
						icon: "none"
					});
					return
				}
				uni.showLoading({
					title:'正在添加...'
				})
				// console.log('打印商品的信息')
				// console.log(that.selectGoodList)
    //            return
				/*
				  * 1. StoreID如果选中商品没有仓库，则赋值表头仓库
				  * 2. IsGift如果没有赠品 赋默认值 ‘否’
				  * 3. Amount 如果没有金额 则算计金额
				*/
				   // for(var i in that.selectGoodList){
					   if(that.selectGoodList["StoreID"] ==""||that.selectGoodList["StoreID"] ==undefined){
					   	that.selectGoodList["StoreID"] = that.StoreID
					   	that.selectGoodList["stockName"] = that.stockName
					   }
					   if(that.selectGoodList["IsGift"] ==""||that.selectGoodList["IsGift"] ==undefined){
					   	that.selectGoodList["IsGift"] ='0'
					   }
					   if(that.Isdistribution == 1){
					   		if(that.selectGoodList["StoreID2"] == ""|| that.selectGoodList["StoreID2"] == undefined){
					   			that.selectGoodList.StoreID2 = that.StoreID2
					   			that.selectGoodList["stockName"] = that.stockName2
					   			}
					   						   // console.log(that.Isdistribution)
					   						   // console.log(that.selectGoodList)
					   }
					   console.log(that.StoreID2)
					   console.log(that.selectGoodList)
					   // return
					   if(that.selectGoodList["Amount"] == ""|| that.selectGoodList["Amount"] ==undefined){
					   	 console.log('价格跟踪返回的值')
						 // console.log(that.prices())
						 that.prices()
						 // that.selectGoodList["Amount"] == that.prices()
					   	// that.computPrice(that.selectGoodList)
					   }else{
						   // //console.log(that.selectGoodList)
						   				// return
						   				//判断是否在单据里面
										uni.hideLoading()
						   				var result = that.Isbill(that.selectGoodList)
						   				// return
						   				//console.log(result)
						   				//console.log(that.selectGoodList)
						                 var Good = that.selectGoodList
						   // if(that.selectGoodList["Amount"] ==""||that.selectGoodList["Amount"] ==undefined){
						   // 			that.selectGoodList["Amount"] = 0	
						   // 			that.selectGoodList["Price"] = 0	
						   // }
						   				//如果等于1表示不存在需要提示用户是否继续添加
						   				if(result.Isbills == 0){
						   					GetApi.showConfirm("源单明细中没有此商品,是否添加？", function(state) {
						   						if (state) {
													that.selectGoodList.Amount = that.computPrice(that.selectGoodList.Price);
						   							that.$eventHub.$emit('Addfires', JSON.stringify(that.selectGoodList));
						   							uni.navigateBack({
						   								delta: 1
						   							})
						   						}
						   					})
						   				}else if(result.Isgreater== 1){
						   					GetApi.showConfirm("录入的数量大于源单数量,是否添加？", function(state,) {
						   						if (state) {
													that.selectGoodList.Amount = that.computPrice(that.selectGoodList.Price);
						   							that.$eventHub.$emit('Addfires', JSON.stringify(that.selectGoodList));
						   							uni.navigateBack({
						   								delta: 1
						   							})
						   						}
						   					})
						   				}else{
						   					console.log('----------------------')
						   					console.log(Good)
						   					console.log(JSON.stringify(Good))
						   					console.log('这是一个打印的---')
											that.selectGoodList.Amount = that.computPrice(that.selectGoodList.Price);
						   					this.$eventHub.$emit('Addfires', JSON.stringify(that.selectGoodList));
						   					uni.navigateBack({
						   						delta: 1
						   					})
						   				}
					   }
				   // }
				
				// return
				////console.tablele(that.selectGoodList);
			},
			//判断是否在单据里面  判断商品数量是否大于单据数量
			//判断录入数量是否大于源单数量
			Isbill:function(data){
				var result = {
					Isbills:0,
					Isgreater:0,
				}
				var that = this;
				var batchs = false;
				var delivery = false;
				if(that.batch == 1){
					batchs = true
				}
				if(that.Isdistribution == 1){
					delivery = true
				}
				for(var i in this.Order){
					console.log('是否相等-----------------------------')
					console.log(CommonFun.isequality(this.Order[i],data,batchs,delivery))
					//如果等于true   存在的商品与添加的商品数量想加  用于判断是否大于源单数量
					if(CommonFun.isequality(this.Order[i],data,batchs,delivery) == true){
							data["nnnqty"] = parseFloat(data["Qty"])+parseFloat(this.Order[i]["Qty"])
					}
				}
				console.log('数组对比');
				console.log(data);
				console.log(this.tmpGoods);
				var tmpGoods = this.tmpGoods
				// var newdata = data
					for(var j in tmpGoods){
						    // data["IsGift"] = data["IsGift"] == "0"?false:true;
							tmpGoods[j]["IsGift"] = tmpGoods[j]["IsGift"] == false || "0"?"0":"1";
							tmpGoods[j]["Qty"] = parseFloat(tmpGoods[j]["Qty"])
                            if(CommonFun.isequality(tmpGoods[j],data,batchs,delivery) == true){
								if(that.batch == 1){
									console.log('---------不需要批号---------不需要---------')
									result.Isbills = 1;
									if ((parseFloat(data["nnnqty"])) > (parseFloat(tmpGoods[j]["UNQTY"]))) {
										result.Isgreater = 1;
									}else{
										if((parseFloat(data["Qty"])) > (parseFloat(tmpGoods[j]["UNQTY"]))){
											result.Isgreater = 1;
										}
									}
								}else{
									console.log('-----需要验证需要验证需要验证需要验证------')
									if(that.isnulls(tmpGoods[j]["BatchNo"]) == that.isnulls(data["BatchNo"])
									&& that.isnulls(that.timesubstr(tmpGoods[j]["ProductionDate"])) == that.isnulls(that.timesubstr(data["ProductionDate"]))
									&& that.isnulls(that.timesubstr(tmpGoods[j]["validityDate"])) == that.isnulls(that.timesubstr(data["validityDate"]))
									){
										
										if(that.Isdistribution == 1){
											if(tmpGoods[j]["StoreID2"] == data["StoreID2"]){
												result.Isbills = 1;
												if(that.isquote == 1){
													if (parseFloat(data["nnnqty"]) > parseFloat(tmpGoods[j]["UNQTY"])) {
														result.Isgreater = 1;
													}else{
														if((parseFloat(data["Qty"])) > (parseFloat(tmpGoods[j]["UNQTY"]))){
															result.Isgreater = 1;
														}
													}
												}else if(that.isquote == 2){
													if (parseFloat(data["nnnqty"]) > parseFloat(tmpGoods[j]["Qty"])) {
														result.Isgreater = 1;
													}else{
														if((parseFloat(data["Qty"])) > (parseFloat(tmpGoods[j]["Qty"]))){
															result.Isgreater = 1;
														}
													}
												}
											}
										}else{
										   result.Isbills = 1;
										   if(that.isquote == 1){
										   	if (parseFloat(data["nnnqty"]) > parseFloat(tmpGoods[j]["UNQTY"])) {
										   		result.Isgreater = 1;
										   	}else{
										   		if((parseFloat(data["Qty"])) > (parseFloat(tmpGoods[j]["UNQTY"]))){
										   			result.Isgreater = 1;
										   		}
										   	}
										   }else if(that.isquote == 2){
										   	if (parseFloat(data["nnnqty"]) > parseFloat(tmpGoods[j]["Qty"])) {
										   		result.Isgreater = 1;
										   	}else{
										   		if((parseFloat(data["Qty"])) > (parseFloat(tmpGoods[j]["Qty"]))){
										   			result.Isgreater = 1;
										   		}
										   	}
										   }	
										}
									}
								}
							}
					}
				// }
				return result
			},
			isnulls:function(e){
				return e == "" || typeof e == 'undefined' ?"":e
			},
			// 日期截取
			timesubstr:function(e){
				return e == ""|| e == undefined ? e : e.substring(0,10)
			},
			//价格跟踪
			prices:function(){
				// //console.log('打印=============')
				var that = this;
				let data = {
					// this.NowSelectGoods
					ClientID :this.ClientID,
					StoreID:that.selectGoodList["StoreID"],
					BillName: that.BillName,
					GoodsID:that.selectGoodList["GoodsID"],
					UnitID:that.selectGoodList["UnitID"],
					URate:that.selectGoodList["urate"],
					// VIPID:''
				}
				 GetApi.XH_Get_PriceFollowMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							GetApi.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							GetApi.showTip(res.data.ErrorMsg);
						} else {
							console.log('价格跟踪的第一个')
							console.log(parseFloat(res.data.ResultMsg[0].Price))
							// res.data.ResultMsg[0]["Price"] =  
							that.selectGoodList.Price = parseFloat(res.data.ResultMsg[0].Price)
							that.selectGoodList.Amount = that.computPrice(parseFloat(res.data.ResultMsg[0].Price));
							console.log('计算后的数组')
							console.log(that.selectGoodList)
							uni.hideLoading()
							var result = that.Isbill(that.selectGoodList)
											// return
											//console.log(result)
											//console.log(that.selectGoodList)
							              var Good = that.selectGoodList
							// if(that.selectGoodList["Amount"] ==""||that.selectGoodList["Amount"] ==undefined){
							// 			that.selectGoodList["Amount"] = 0	
							// 			that.selectGoodList["Price"] = 0	
							// }
											//如果等于1表示不存在需要提示用户是否继续添加
											if(result.Isbills == 0){
												GetApi.showConfirm("源单明细中没有此商品,是否添加？", function(state) {
													if (state) {
														that.$eventHub.$emit('Addfires', JSON.stringify(that.selectGoodList));
														uni.navigateBack({
															delta: 1
														})
													}
												})
											}else if(result.Isgreater== 1){
												GetApi.showConfirm("录入的数量大于源单数量,是否添加？", function(state,) {
													if (state) {
														that.$eventHub.$emit('Addfires', JSON.stringify(that.selectGoodList));
														uni.navigateBack({
															delta: 1
														})
													}
												}) 
											}else{
												console.log('----------------------')
												console.log(Good)
												console.log(JSON.stringify(Good))
												console.log('这是一个打印的---')
												that.$eventHub.$emit('Addfires', JSON.stringify(Good));
												uni.navigateBack({
													delta: 1
												})
											}
						}
					} else {
							GetApi.showTip("服务器错误!");
					}
				});
			},
			//计算金额
			computPrice(item){
				var Price = 0;
				//console.log('进来的参数')
				//console.log(item)
				// parseFloat((item.PFPrice*item.Qty*(item.Discount/100)*(1+item.Tax/100))).toFixed(2);
				Price = parseFloat((item*this.selectGoodList.Qty*(this.selectGoodList.Discount/100)*(1+this.selectGoodList.Tax/100))).toFixed(2);
				//console.log('计算后的金额')
				//console.log(Price)
				return Price;
			},
			//商品设置
			lookGoodInfo(index) {
				console.log('商品设置')
				console.log(this.GoodList[index])
				
				if(this.GoodList[index].StoreID2 == "" || this.GoodList[index].StoreID2 == undefined){
					this.GoodList[index].StoreID2 = this.GoodList[index].StoreID2 
				}
				// this.StoreID2
				console.log(this.GoodList[index])
				// var goodData = JSON.stringify(this.GoodList[index]);
				var statu = false
				if(this.Isdistribution == true){
					statu = true
				}
				console.log('源单商品')
				console.log(this.tmpGoods)
				// return
				var goodData  = JSON.stringify(this.isidentical(this.tmpGoods,this.GoodList[index],statu))
				//console.log(this.StoreID)
				this.AddListen();
				uni.navigateTo({ 
					url: './goodInfoDetail?goodData=' + goodData + "&StoreID=" + this.StoreID + "&selectIndex=" + index
					+"&orderType="+this.orderType+"&Isdistribution="+this.Isdistribution+"&name="+this.BillName
					+"&ClientID="+this.ClientID
					
				})
			},
			isidentical:function(Good,Sood,delivery){
				
				console.log('源单商品')
				console.log(Good)
				for(var i in Good){
				console.log('源单商品合并==================================')
				// console.log(Good["BarCode"] == Sood["BarCode"],'条码','源单'+Good["BarCode"],'选中的商品'+Sood["BarCode"])
				console.log(Good[i]["GoodsID"] == Sood["GoodsID"],'商品','源单'+Good[i]["GoodsID"],'选中的商品'+Sood["GoodsID"])
				console.log(Good[i]["StoreID"] == this.StoreID,'仓库','源单'+Good[i]["StoreID"],'选中的商品'+this.StoreID)
				console.log(Good[i]["UnitID"] == Sood["UnitID"],'单位','源单'+Good[i]["UnitID"],'选中的商品'+Sood["UnitID"])
				// console.log(Good["IsGift"] == Sood["IsGift"],'赠品','源单'+Good["IsGift"],'选中的商品'+Sood["IsGift"])
				if(Good[i]["GoodsID"] == Sood["GoodsID"]
				&& Good[i]["StoreID"] == this.StoreID
				&& Good[i]["UnitID"] == Sood["UnitID"]
				// && Good["IsGift"] == Sood["IsGift"]
				){
					if(delivery){
						if(Good["StoreID2"] == Sood["StoreID2"]){
						Sood["Discount"] = Good[i]["Discount"]
						Sood["Tax"] = Good[i]["Tax"]
						Sood["Price"] = Good[i]["Price"]
						Sood["IsGift"] = Good[i]["IsGift"]
						}
					}else{
						
						Sood["Discount"] = Good[i]["Discount"]
						Sood["Tax"] = Good[i]["Tax"]
						Sood["Price"] = Good[i]["Price"]
						Sood["IsGift"] = Good[i]["IsGift"]
					}
					
				}
				}
				return Sood
			},
			AddListen() {
				var that = this;
				this.$eventHub.$on('GoodStting', function(data) {
					var GoodsItem = JSON.parse(data.NewGoodInfo);
					var Gindex = data.index
					console.log('商品设置返回的参数')
					console.log(GoodsItem)
					//console.log(Gindex)
					//需要单独赋值
					that.GoodList[Gindex].Amount = GoodsItem.Amount;
					that.GoodList[Gindex].StoreID = GoodsItem.StoreID;
					that.GoodList[Gindex].StoreID2 = GoodsItem.StoreID2;
					that.GoodList[Gindex].UnitID = GoodsItem.UnitID;
					that.GoodList[Gindex].UnitName = GoodsItem.UnitName;
					that.GoodList[Gindex].IsGift = GoodsItem.IsGift;
					that.GoodList[Gindex].BatchNo = GoodsItem.BatchNo;
					that.GoodList[Gindex].ProductionDate = GoodsItem.ProductionDate;
					that.GoodList[Gindex].validityDate = GoodsItem.validityDate;
					that.GoodList[Gindex].Tax = GoodsItem.Tax;
					that.GoodList[Gindex].Price = GoodsItem.Price;
					that.GoodList[Gindex].Discount = GoodsItem.Discount;
					that.GoodList[Gindex].Qty = GoodsItem.Qty;
					that.GoodList[Gindex].Remark = GoodsItem.Remark;
					that.GoodList[Gindex].urate = GoodsItem.urate;
					console.log('设置成功')
					console.log(that.GoodList[Gindex])
					// that.GoodList[Gindex].StoreName = GoodsItem.StoreName;
					that.$eventHub.$off('GoodStting');
					
				});
			},
			// 单选
			selectNowGood(index) {
			   this.checkindex  = this.checkindex==index?-1:index
			},
			//查询商品
			getGoodList(filter) {
				if (filter == undefined) {
					filter = {
						StoreID: this.StoreID,
						BillName:this.BillName
					}
				}
				//console.log(filter);
				var that = this; 
				this.checkGoodList = [];
				this.GoodList = []
				GetApi.Get_GoodsMessage(filter, function(res) {
					uni.hideLoading();
					if (res.data.ErrorMsg == "获取登录信息失败") {
						GetApi.showTip("登录超时");
                          // if (res.data.ErrorMsg == "获取登录信息失败") {
                          // 	GetApi.showTip("登录超时");
                          // } else if (res.data.ErrorMsg != "") {
                          // 	GetApi.showTip(res.data.ErrorMsg);
                          // } else if(res.data.ResultMsg.length == 0) {
                          // 	GetApi.showTip('查无数据');
                          // }else{
					} else if (res.data.ErrorMsg != "") {
						//console.log(res.data.ErrorMsg);
                         GetApi.showTip(res.data.ErrorMsg);
					} else if(res.data.ResultMsg.length == 0){
						GetApi.showTip('查无数据');
					}else {
						//console.log(res);
						var item = {};
						res.data.ResultMsg.forEach((item, index) => {
							item = {
								checked: false
							};
							that.checkGoodList.push(item);
							res.data.ResultMsg[index].Qty = 1;
							// this.NowSelectGoods.Qty = this.GoodsQty;
							res.data.ResultMsg[index].Discount = 100;
							res.data.ResultMsg[index].Tax = 0;
							res.data.ResultMsg[index].Remark = "";
							res.data.ResultMsg[index].GoodsStorm = 0;
							res.data.ResultMsg[index].isSet = false;
							// res.data.ResultMsg[index].PFPrice = that.computPrice(res.data.ResultMsg[index]);
							res.data.ResultMsg[index].stockqty = Math.round(res.data.ResultMsg[index].stockqty * 100) / 100;
							
							var pr = 0;
							if(that.BillName == "采购入库单" ||that.BillName == "采购退货单"){
								pr = Math.round(res.data.ResultMsg[index].InPrice * 100) / 100;
							}else if(that.BillName == "销售出库单" ||that.BillName == "销售退货单"){
								pr = Math.round(res.data.ResultMsg[index].SalePrice * 100) / 100;
							}else if(that.BillName == "配送出库单" ||that.BillName == "配送退回单"){
								pr = Math.round(res.data.ResultMsg[index].Price3 * 100) / 100;
							}
							// Price
							res.data.ResultMsg[index].Price = pr;
						});
						that.GoodList = res.data.ResultMsg;
					}
				});
			},
			// 计算折扣后商品价格
			// computPrice(item){
			// 	var Price = null
			// 	Price = parseFloat((item.PFPrice*item.Qty*(item.Discount/100)*(1+item.Tax/100))).toFixed(2);
				
			// 	return Price;
			// },
			back: function() {
				uni.navigateBack({
					delta: 1
				})
			},
			navigatorTo(e) {
				if (this.type == 0) {
					uni.navigateTo({
						url: '../detail/detail',
					});
				}
			},
			upper: function(e) {
				//console.log(e)
			},
			lower: function(e) {
				//console.log(e)
			},
			tel: function() {
				// this.current = -1;
				// 调起条码扫描
				var that = this;
				uni.scanCode({
					scanType: 'barCode',
					success: function(res) {
						//console.log(res.result);
						that.GetBarcodeGoodsMessageModel(res.result);
					},
					fail(e) {
						//console.log(e);
					}
				});
			},
			//通过条码扫描商品
			GetBarcodeGoodsMessageModel(barcode) {
				//console.log("barcode", barcode);
				let data = {
					BillName: this.BillName,
					BarCode: barcode,
					Model: "="
				};
				var that = this;
				that.GoodList = [];
				that.checkGoodList = [];
				GetApi.GetBarcodeGoodsMessageModel(data, function(res) {
					//console.log(res.data.ResultMsg);
					//console.log("---");
					// if(res.data.ResultMsg)
					
					if (res.data.ErrorMsg == "获取登录信息失败") {
						GetApi.showTip("登录超时");
					} else if (res.data.ErrorMsg != "") {
						GetApi.showTip(res.data.ErrorMsg);
					} else if(res.data.ResultMsg.length == 0) {
						GetApi.showTip('查无数据');
					}else{
						let item = {};
						res.data.ResultMsg.forEach((item, index) => {
							item = {
								checked: false
							};
							that.checkGoodList.push(item);
							res.data.ResultMsg[index].Qty = 1;
							// this.NowSelectGoods.Qty = this.GoodsQty;
							res.data.ResultMsg[index].Discount = 100;
							res.data.ResultMsg[index].Tax = 0;
							res.data.ResultMsg[index].Remark = "";
							res.data.ResultMsg[index].GoodsStorm = 0;
							// res.data.ResultMsg[index].PFPrice = that.computPrice(res.data.ResultMsg[index]);
							res.data.ResultMsg[index].stockqty = Math.round(res.data.ResultMsg[index].stockqty * 100) / 100;
							res.data.ResultMsg[index].PFPrice = Math.round(res.data.ResultMsg[index].PFPrice * 100) / 100;
						});
						that.GoodList = res.data.ResultMsg;
					}
						
						
					
				})
			},
			scroll: function(e) {
				//console.log(e)
				this.old.scrollTop = e.detail.scrollTop
			},
			
			
		}
	}
</script>
<style>
	@import url("./SelectedGoods.css");
	@import "../../static/uni.css";
	/* uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked{
		color: red !important;
	} */
</style>
